using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Collections;

namespace Com.Phyfun.Business
{
    public class LangHelper
    {
        private string SessionKeyLang="Session_Key_Lang";

        public string CurrentLang
        {
            get
            {
                string lang = string.Empty;
                if (HttpContext.Current.Session[SessionKeyLang] == null)
                {
                    if (HttpContext.Current.Request.UserLanguages != null)
                    {
                        string userLanguage = HttpContext.Current.Request.UserLanguages[0];
                        if (userLanguage.Length >= 2)
                        {
                            lang = userLanguage.Substring(0, 2);
                        }
                        IList list = Sessions.GetListByHQL("Select From Lang as lang");
                        bool isDefinedLang = false;
                        for (int i = 0; i < list.Count; i++)
                        {
                            Lang langObj = (Lang)list[i];
                            if (langObj.LangName == lang)
                            {
                                isDefinedLang = true;
                                break;
                            }
                        }
                        if (!isDefinedLang)
                        {
                            lang = "en";
                        }
                    }
                    else
                    {
                        lang = "en";
                    }
                    HttpContext.Current.Session[SessionKeyLang] = lang;
                }
                else
                {
                    lang = HttpContext.Current.Session[SessionKeyLang].ToString();
                }
                return lang;
            }
            set
            {
                HttpContext.Current.Session[SessionKeyLang] = value;
            }
        }
    }
}
